<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Monolog\Logger;
use Yansongda\Pay\Pay;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //支付容器注册
        //往服务容器中注入名为alipay的单例对象
        $this->app->singleton('alipay',function (){
            //配置文件
            $config = config('pay.alipay');
            //服务器回调地址
            //$config['notify_url'] = route('payment.alipay.notify');
            $config['notify_url'] = 'http://requestbin.leo108.com/vaul5hva';
            //前端回调地址
            $config['return_url'] = route('payment.alipay.return');


            //当前项目运行环境是否为上线环境
            if (app()->environment() !== 'production'){
                $config['mode']      = 'dev';
                $config['log']['level']  = Logger::DEBUG;
            }else{
                $config['log']['level']  = Logger::WARNING;
            }
            //调用 Yansonda\Pay 来创建支付宝支付对象

            return Pay::alipay($config);
        });

        $this->app->singleton('wechat_pay',function (){
            $config = config('pay.wechat');
            //服务端回调地址
            $config['notify_url'] = 'http://requestbin.fullcontact.com/[替换成你自己的url]';
            //当前项目运行环境是否为上线环境
            if (app()->environment() !== 'production'){
                $config['mode']      = 'dev';
                $config['log']['level']  = Logger::DEBUG;
            }else{
                $config['log']['level']  = Logger::WARNING;
            }
            //调用 Yansonda\Pay 来创建支付宝支付对象

            return Pay::wechat($config);
        });
    }
}
